<template>
    <view>
        <slot></slot>
        <uni-load-more :status="status" :icon-size="14" :content-text="contentText"/>
    </view>
</template>

<script>
    export default {
        props: {},
        data() {
            return {
                status: 'noMore',
                contentText: {
                    contentdown: '上拉加载更多~',
                    contentrefresh: '加载中',
                    contentnomore: '没有发现更多数据~'
                },
                page: {
                    current: 1,
                    size: 10
                }
            }
        },
        methods: {
            // options.pullDownRefresh = true 是下拉刷新，否则为上拉触底加载更多
            loadData(url, options) {
                if (options.pullDownRefresh) {
                    this.page.current = 1
                } else if(options.data.current) {

                }else {
                    this.page.current++
                }

                this.status = 'loading';

                let _data = {}
                Object.assign(_data,options.data || {})

                _data.current = _data.current || this.page.current
                _data.size = this.page.size
               // uni.showLoading({title: '加载中'})
                return new Promise((resolve, reject) => {
                    this.$http.get(url, {params: _data}).then(res => {
                        this.status = (res.data.current < res.data.pages && !(options.data.current == this.page.current)) ? 'more' : 'noMore'
                        resolve(res)
                    }).catch(res => {
                        this.status = 'noMore'
                        reject(res)
                    }).finally(() => {
                        if (options.pullDownRefresh) {
                            uni.stopPullDownRefresh()
                        }
                       // uni.hideLoading()
                    })
                })

            }
        }
    }
</script>

<style>

</style>
